package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderSettingMapper extends BaseMapper<OrderSetting> {
    @Select("select  day(orderdate) as date , number ,reservations  from  t_ordersetting  where  ORDERDATE BETWEEN #{beginDate} and #{endDate}")
    List<Map> findOrderSettingsData(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Update("update t_ordersetting set NUMBER=#{num} where ORDERDATE=#{dateparam}")
    void updateOrderSettingData(@Param("dateparam") String dateparam, @Param("num") Integer num);

    @Select("select count(1) from  t_ordersetting  where  ORDERDATE=#{orderDate} and number>RESERVATIONS")
    int isOrderfull(@Param("orderDate") String orderDate);

    @Update("update t_ordersetting set RESERVATIONS=RESERVATIONS+1 where ORDERDATE = #{orderDate}")
    void updateReseversByData(@Param("orderDate") String orderDate);
}
